// $Id: request.h 94 2011-10-19 12:48:16Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef CODEC_REQUEST_H_
#define CODEC_REQUEST_H_

#include <sys/types.h>

enum niortsp_request_decoder_state {
	NIORTSP_REQUEST_LINE,
	NIORTSP_REQUEST_HEADERS,
	NIORTSP_REQUEST_CONTENT,
};

struct niortsp_headers_decoder;

struct niortsp_request;

struct niortsp_request_decoder {
	struct niortsp_headers_decoder *decoder;
	enum niortsp_request_decoder_state state;
	struct niortsp_request *request;
	ssize_t offset1;
	ssize_t offset2;
};

struct niortsp_request_decoder *niortsp_request_decoder_new(void);

void niortsp_request_decoder_free(struct niortsp_request_decoder *codec);

int niortsp_request_decoder_reset(struct niortsp_request_decoder *decoder,
		struct zcbuffer *buffer);

size_t niortsp_request_decoder_position(
		struct niortsp_request_decoder *decoder);

struct zcbuffer;

int niortsp_request_decoder_parse(
		struct niortsp_request_decoder *decoder,
		struct zcbuffer *buffer, struct niortsp_request **request);

#endif /* CODEC_REQUEST_H_ */
